package foop14bsp1.model;

import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

public class GameBlock extends JLabel {

	private static final long serialVersionUID = -6162853272023770779L;

	private int x, y, col, row;
	private int blocksize;
	private GameBlockType type;

	public GameBlock(GameBlockType type, int col, int row, int blocksize) {
		super("");
		this.col = col;
		this.row = row;
		this.blocksize = blocksize;
		this.x = col * blocksize;
		this.y = row * blocksize;
		this.type = type;
		this.setBounds(this.x, this.y, blocksize, blocksize);
		this.setOpaque(true);

		ImageIcon icon = null;

		switch (type) {
		case FREE:
			icon = new ImageIcon("ressources/grass.gif");
			break;
		case WALL:
			icon = new ImageIcon("ressources/wall.gif");
			break;
		case CHEESE:
			icon = new ImageIcon("ressources/cheese.gif");
			break;
		case CLOSEDDOOR:
			icon = new ImageIcon("ressources/closed_door.png");
			break;
		case OPENDOOR:
			icon = new ImageIcon("ressources/open_door.png");
			break;
		default:
			icon = new ImageIcon("ressources/grass.gif");
		}
		icon.setImage(icon.getImage().getScaledInstance(blocksize, blocksize,
				Image.SCALE_DEFAULT));
		this.setIcon(icon);
	}

	public int getCol() {
		return this.col;
	}

	public int getRow() {
		return this.row;
	}

	public GameBlockType getType() {
		return this.type;
	}

	public void setType(GameBlockType t) {
		ImageIcon icon = new ImageIcon();
		switch(t) {
		case FREE:
			this.type = GameBlockType.FREE;
			icon = new ImageIcon("ressources/grass.gif");
			break;
		case OPENDOOR:
			this.type = GameBlockType.OPENDOOR;
			icon = new ImageIcon("ressources/open_door.png");
			break;
		case CLOSEDDOOR:
			this.type = GameBlockType.CLOSEDDOOR;
			icon = new ImageIcon("ressources/closed_door.png");
			break;
		case MOUSE1:
			this.type = GameBlockType.MOUSE1;
			icon = new ImageIcon("ressources/mouse1.png");
			break;
		case MOUSE2:
			this.type = GameBlockType.MOUSE2;
			icon = new ImageIcon("ressources/mouse2.png");
			break;
		case MOUSE3:
			this.type = GameBlockType.MOUSE3;
			icon = new ImageIcon("ressources/mouse3.png");
			break;
		case MOUSE4:
			this.type = GameBlockType.MOUSE4;
			icon = new ImageIcon("ressources/mouse4.png");
			break;
		default:
			this.type = GameBlockType.ERROR;
			icon = new ImageIcon("ressources/grass.gif");
		}
		icon.setImage(icon.getImage().getScaledInstance(blocksize,
				blocksize, Image.SCALE_DEFAULT));
		this.setIcon(icon);
	}
}
